<?
//=======================================
//###################################
// Kayako Web Solutions
//
// Source Copyright 2001-2004 Kayako Infotech Ltd.
// Unauthorized reproduction is not allowed
// License Number: $%LICENSE%$
// $Author: vshoor $ ($Date: 2005/07/07 18:07:59 $)
// $RCSfile: report_populardownloads.php,v $ : $Revision: 1.1 $ 
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//
//###################################
//=======================================


if (!defined("INSWIFT")) {
	trigger_error("Unable to process $PHP_SELF", E_USER_ERROR);
}

$_items = array();
$_viewcount = 0;
$_limit = 15;

if ($_GET["do"] == "chart")
{
	$_limit = 8;
}

$dbCore->query("SELECT *, downloaditems.displayorder AS itemdisplayorder, downloaditems.title AS itemtitle, downloaditems.dateline AS itemdateline FROM `". TABLE_PREFIX ."downloaditems` AS downloaditems LEFT JOIN `". TABLE_PREFIX ."downloadcategories` AS downloadcategories ON (downloaditems.downloadcategoryid = downloadcategories.downloadcategoryid) ORDER BY downloaditems.totaldownloads ". iif($_GET["do"]=="chart", "ASC", "DESC") ." LIMIT ". intval($_limit) .";");
while ($dbCore->nextRecord())
{
	$_items[$dbCore->Record["downloaditemid"]] = $dbCore->Record;
	$_viewcount += $dbCore->Record["totaldownloads"];
}

/**
* ###############################################
* SHOW CHART?
* ###############################################
*/
if ($_GET["do"] == "chart")
{
	$chart['chart_bg'] = array('positive_alpha' => 0);
	// Prepeare the data
	$_chartdata = array("");
	$_chartvalues = array("");
	$_seriesexplode = array();
	$index = 0;

	foreach ($_items as $key=>$val)
	{
		$_chartdata[] = $val["downloaditemid"];
		if (!empty($val["totaldownloads"]))
		{
			$_chartvalues[] = ($val["totaldownloads"]/$_viewcount)*100;
		} else {
			$_chartvalues[] = 0;
		}
	}

	$chart[ 'axis_category' ] = array ( 'font'=>"verdana", 'bold'=>true, 'size'=>10, 'color'=>"333333", 'alpha'=>100, 'skip'=>0, 'orientation'=>"horizontal" ); 
	$chart[ 'axis_ticks' ] = array ( 'value_ticks'=>false, 'category_ticks'=>true, 'major_thickness'=>2, 'minor_thickness'=>1, 'minor_count'=>1, 'major_color'=>"222222", 'minor_color'=>"222222" ,'position'=>"centered" );
	$chart[ 'axis_value' ] = array ( 'min'=> 0 ,'max'=> 100 , 'font'=>"arial", 'bold'=>true, 'size'=>10, 'color'=>"ffffff", 'alpha'=>0, 'steps'=>6, 'prefix'=>"", 'suffix'=>"", 'decimals'=>0, 'separator'=>"", 'show_min'=>true );

	$chart[ 'chart_bg' ] = array ( 'positive_color'=>"F7FAFF", 'negative_color'=>"ff0000", 'positive_alpha'=>50, 'negative_alpha'=>25);
	$chart[ 'chart_border' ] = array ( 'color'=>"6393DF", 'top_thickness'=>1, 'bottom_thickness'=>1, 'left_thickness'=>3, 'right_thickness'=>1 );
	$chart[ 'chart_data' ] = array ( $_chartdata, $_chartvalues);
	$chart[ 'chart_grid_h' ] = array ( 'alpha'=>4, 'color'=>"000000", 'thickness'=>4 );
	$chart[ 'chart_rect' ] = array ( 'x'=>60, 'y'=>5, 'width'=>320, 'height'=>160 );
	$chart[ 'chart_type' ] = "bar"; 
	$chart[ 'chart_value' ] = array ( 'color'=>"000000", 'alpha'=>75, 'font'=>"verdana", 'bold'=>true, 'size'=>10, 'position'=>"center", 'prefix'=>"", 'suffix'=>"", 'decimals'=>0, 'separator'=>"", 'as_percentage'=>true );

	$chart[ 'legend_rect' ] = array ( 'x'=>-100, 'y'=>-100, 'width'=>10, 'height'=>10, 'margin'=>5 ); 

	$chart['series_color'] = array("B0CAF3");

	SendChartData ($chart);

	exit;
}

$interface->staffHeader($_SWIFT["language"]["downloads"]." &gt; ".$_SWIFT["language"]["reports"], 5);

$interface->staffNavBar('<a href="index.php?_m=downloads&_a=managefiles" title="'.$_SWIFT["language"]["downloads"].'">'.$_SWIFT["language"]["downloads"].'</a> &raquo; <a href="index.php?_m=downloads&_a=reports&type=populardownloads" title="'.$_SWIFT["language"]["reports"].'">'.$_SWIFT["language"]["reports"].'</a> &raquo; <a href="index.php?_m=downloads&_a=reports&type=populardownloads" title="'.$_SWIFT["language"]["populardownloads"].'">'.$_SWIFT["language"]["populardownloads"].'</a>', "", 5);

?>
<table width="100%" border="0" cellspacing="0" cellpadding="3">
<tr>
<td width="300" align="left" valign="top">
<?
	echo InsertChart($_SWIFT["swiftpath"]."includes/Graph/charts.swf", "index.php?_m=downloads&_a=reports&type=populardownloads&do=chart", 400, 350, "666666", true);
?>
</td>
<td align="left" valign="top">
<table width="100%"  border="0" cellspacing="1" cellpadding="3" class="tborder">
<tr class="tabletitlerow">
<td width="1" align="center" nowrap>&nbsp;ID</td>
<td>&nbsp;<?=$_SWIFT["language"]["filetitle"]?></td>
<td width="180" align="center">&nbsp;<?=$_SWIFT["language"]["dlitemfilename"]?></td>
<td width="100" align="center">&nbsp;<?=$_SWIFT["language"]["dlitemfilesize"]?></td>
<td width="60" align="center">&nbsp;<?=$_SWIFT["language"]["downloadno"]?></td>
</tr>
<?

foreach ($_items as $key=>$val)
{
	$extension = getFileExtension($val["filename"]);
	$mimedata = $mimelist[$extension];
	if (!empty($mimedata[1]))
	{
		$filenamed = '<table width="100%"  border="0" cellspacing="0" cellpadding="2"><tr><td width="1"><img src="'. $_SWIFT["themepath"] . $mimedata[1] .'" border="0" /></td><td align="left"><span class="smalltext">'. $val["filename"] .'</span></td></tr></table>';
	} else {
		$filenamed = '<table width="100%"  border="0" cellspacing="0" cellpadding="2"><tr><td align="left"><span class="smalltext">'. $val["filename"] .'</span></td></tr></table>';
	}
	?>
	<tr class="<?=getRowBG()?>">
	<td width="1" align="center"><?=intval($val["downloaditemid"]);?></td>
	<td><?
	echo '<table width="100%"  border="0" cellspacing="0" cellpadding="2"><tr><td width="1"><img src="'. $_SWIFT["themepath"] . iif($val["categorytype"]==SWIFTPUBLIC||$val["categorytype"]=="", "icon_public", "icon_private") .'.gif" border="0" /></td>'. iif(!empty($val["itempassword"]), '<td width="1"><img src="'. $_SWIFT["themepath"] . 'icon_lock.gif" border="0" /></td>') .'<td align="left"><span class="smalltext"><a href="index.php?_m=downloads&_a=editfile&downloaditemid='. $val["downloaditemid"] .'"><b>'. $val["itemtitle"] .'</b></a></span></td></tr></table>';
	?></td>
	<td width="180" align="center"><?=$filenamed?></td>
	<td width="100" align="center"><?=formattedSize($val["filesize"]);?></td>
	<td width="60" align="center"><?=intval($val["totaldownloads"]);?></td>
	</tr>
	<?
}
?>
</table>
</td>
</tr>
</table>
<?

$interface->staffFooter();

?>